import  Vue  from  'vue'

import  Vuex  from 'vuex'


Vue.use(Vuex)
import  menu  from  './modules/menu'  
//role 和menu是模块名
import role from './modules/role'
import  user  from './modules/manger'
import cate  from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import member from './modules/member'
import seck from './modules/seck'
import banner from './modules/banner'

export default   new  Vuex.Store({


     state:{
        userInfo:sessionStorage.getItem('user')?JSON.parse(sessionStorage.getItem('user')):null
           
    },

    getters:{
           getUserInfo(state){
              return state.userInfo
           }
    },
    mutations:{
            
        CHANG_USERINFO(state,payload){
            if(payload){
               state.userInfo=payload
               sessionStorage.setItem('user',JSON.stringify(payload))
            }else{
                sessionStorage.removeItem('user')
            }

            

        }
    },
    actions:{
        changeUserInfoAction({commit},payload){
            //提交一个mutation
            commit('CHANG_USERINFO',payload)
        }
    },
   modules:{
       menu,
       role,
       user,
       cate,
       specs,
       goods,
       member,
       seck,
       banner

   }
    
})